const {Router} = require('express')
const router = new Router()
const path = require('path')

const removeFile = require('../../utils/fileUtils/removeFile')

// 引入url
const url = require('../../config/url')

router.post('/deleteFile',function (request, response) {
    const {serverPath} = request.body
    const filePath = serverPath.replace(`${url}public`,path.resolve(__dirname, '../../public'))

    removeFile(filePath,status =>{
        if (status.isSuccess) return response.json({
            code: '200',
            data: 'success',
            msg: '删除文件成功'
        })
        
        return response.json({
            code: '200',
            data: 'error',
            msg: '删除文失败'
        })
    })
})

module.exports = router
